﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BDPAutodetect.Device
{
    /// <summary>
    /// 型号等开关状态
    /// </summary>
    public class SensorSignSwitchStatus
    {
        /// <summary>
        /// 定义一个标识确保线程同步
        /// </summary>
        private readonly object Locker = new object();
        /// <summary>
        /// 工位1启动状态（bit 0:启动；1：非启动）
        /// </summary>
        public bool StationStatus1 { get; set; }
        /// <summary>
        /// 工位2启动状态（bit 0:启动；1：非启动）
        /// </summary>
        public bool StationStatus2 { get; set; }
        /// <summary>
        /// 工位3启动状态（bit 0:启动；1：非启动）
        /// </summary>
        public bool StationStatus3 { get; set; }
        /// <summary>
        /// 待定1
        /// </summary>
        public bool Undetermined1 { get; set; }
        /// <summary>
        /// 待定2
        /// </summary>
        public bool Undetermined2 { get; set; }
        /// <summary>
        /// 待定3
        /// </summary>
        public bool Undetermined3 { get; set; }
        /// <summary>
        /// 待定4
        /// </summary>
        public bool Undetermined4 { get; set; }
        /// <summary>
        /// 待定5
        /// </summary>
        public bool Undetermined5 { get; set; }

        /// <summary>
        /// 更新上袋状态
        /// </summary>
        /// <param name="argByteDataItem">字节数据</param>
        public void UpdateState(byte argByteDataItem)
        {
            lock (Locker)
            {
                this.StationStatus1 = !Convert.ToBoolean((argByteDataItem >> 0) & 0x1);
                this.StationStatus2 = !Convert.ToBoolean((argByteDataItem >> 1) & 0x1);
                this.StationStatus3 = !Convert.ToBoolean((argByteDataItem >> 2) & 0x1);
                this.Undetermined1 = !Convert.ToBoolean((argByteDataItem >> 3) & 0x1);
                this.Undetermined2 = !Convert.ToBoolean((argByteDataItem >> 4) & 0x1);
                this.Undetermined3 = !Convert.ToBoolean((argByteDataItem >> 5) & 0x1);
                this.Undetermined4 = !Convert.ToBoolean((argByteDataItem >> 6) & 0x1);
                this.Undetermined5 = !Convert.ToBoolean((argByteDataItem >> 7) & 0x1);
            }
        }
    }
}
